package com.cib.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.UUID;

/**
 * @描述:
 * @Author: zhangh
 * @Time: 2021/8/17 10:51
 **/
@RestController
public class VerifyController {
    @Autowired
    RestTemplate restTemplate;
    @GetMapping("health")
    public String health(){
        return "OK";
    }

    @PostMapping("syncRedis")
    public String syncRedis(){
        long start = System.currentTimeMillis();
        MultiValueMap<String, String> requestParam = new LinkedMultiValueMap<>();
        requestParam.add("key", "key1");
       requestParam.add("value", String.valueOf(System.currentTimeMillis()));
        String body="";
        try {
           ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://localhost:8882/redis/syncRedis", requestParam, String.class);
           HttpStatus statusCode = responseEntity.getStatusCode();
          body= responseEntity.getBody();
           System.out.println("body:"+body);


       }catch (Exception e){
           e.printStackTrace();
       }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
        return body;

    }

}
